home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / tw14w12s.zoo / tw14w12s / toswin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-06  |  20.6 KB  |  1,006 lines

  1. /*
  2.  * Copyright 1992 Eric R. Smith. All rights reserved.
  3.  * Redistribution is permitted only if the distribution
  4.  * is not for profit, and only if all documentation
  5.  * (including, in particular, the file "copying")
  6.  * is included in the distribution in unmodified form.
  7.  * THIS PROGRAM COMES WITH ABSOLUTELY NO WARRANTY, NOT
  8.  * EVEN THE IMPLIED WARRANTIES OF MERCHANTIBILITY OR
  9.  * FITNESS FOR A PARTICULAR PURPOSE. USE AT YOUR OWN
  10.  * RISK.
  11.  */
  12. #include "xgem.h"
  13. #include <osbind.h>
  14. #include <mintbind.h>
  15. #include <fcntl.h>
  16. #include <signal.h>
  17. #include <minimal.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include "toswin_w.h"
  21. #include "twdefs.h"
  22. #include "twproto.h"
  23. #include <linea.h>
  24.  
  25. extern void free();
  26. void *heapbase = 0;
  27. long heapsize = 96*1024L;
  28. long _stksiz = 6 * 1024L;
  29. long termfunc;
  30.  
  31. WINDOW *focuswin;
  32.  
  33. #ifndef TIOCSWINSZ
  34. #define TIOCGWINSZ    (('T'<< 8) | 11)
  35. #define TIOCSWINSZ    (('T'<< 8) | 12)
  36. #endif
  37.  
  38. /* set if we're running MultiTOS */
  39. int MultiTOS = 0;
  40.  
  41. /* set if we're an accessory under old TOS */
  42. int oldACC = 0;
  43. int global_flag = 0;    /* set to O_GLOBAL if necessary */
  44.  
  45. /* file descriptor of TOSRUN */
  46. int trun_fd;
  47. extern long fd_mask;
  48.  
  49. /* is the "tools" window open? */
  50. int showtools = 1;
  51. int toolx, tooly;    /* location of tools window */
  52.  
  53. /* do we automatically close any windows that have exited? */
  54. int autoclose;
  55.  
  56. /* try to scroll nicely? */
  57. int smoothscroll;
  58.  
  59. /* 1 for "point to type", 0 for "click to type" */
  60. int point_to_type;
  61. WINDOW *toolwindow;
  62.  
  63. MENU *sysbar;        /* the system menu bar */
  64. MENU *globalmenu;
  65. MENU *windowmenu;
  66. MENU *filemenu, *editmenu;
  67. ENTRY *closeentry;
  68. ENTRY *copyentry, *pasteentry;
  69. MENU *gadgmenu;
  70.  
  71. int appl_menus = 1;    /* OK to load/show application menus */
  72. int sys_menu = 1;    /* set if the system menu is being displayed */
  73.  
  74. OBJECT *deskobj;
  75. OBJECT *cutdialog, *fontdial;
  76. OBJECT *menudef_dialog;
  77. OBJECT *winsize_dialog;
  78.  
  79. #define ALLGADGETS 0xfff    /* everything including the INFO line */
  80. #define MINGADGETS 0x01f    /* NAME, CLOSER, FULLER, MOVER, INFO */
  81. #define NOGADGETS  0x000
  82.  
  83. int default_kind = ALLGADGETS;
  84.  
  85. extern char progpath[128];
  86. static char fname[256];
  87. int altrow, altcol;
  88. int stdrow, stdcol;
  89. int altscroll, stdscroll;
  90.  
  91. char stdconfig[128] = "TOSWIN.CNF";
  92. char nullstr[2] = "";
  93.  
  94. int lineAset = 0;
  95. int lineArow, lineAcol;
  96.  
  97. #ifdef OLD_WAY
  98. /*
  99.  * signal handler for dead children
  100.  * all we do is collect (and discard :-( ) the exit code
  101.  * it's up to fd_input() and friends to figure out when no
  102.  * more data exists for a window
  103.  */
  104.  
  105. #define WNOHANG 1
  106.  
  107. void
  108. dead_kid()
  109. {
  110.     long r;
  111.  
  112.     r = Pwait3(WNOHANG, (void *)0);
  113.  
  114. }
  115.  
  116. #endif
  117.  
  118. /*
  119.  * signal handler for SIGINT and SIGQUIT: these get passed along to the
  120.  * process group in the focus window
  121.  */
  122.  
  123. void
  124. send_sig(sig)
  125.     long sig;
  126. {
  127.     TEXTWIN *t;
  128.  
  129.     if (focuswin && focuswin->wtype == TEXT_WIN) {
  130.         t = focuswin->extra;
  131.         if (t->pgrp) {
  132.             (void)Pkill(-t->pgrp, (short)sig);
  133.         }
  134.     }
  135. }
  136.  
  137. void
  138. ignore()
  139. {
  140. }
  141.  
  142. char argstr[128];
  143.  
  144. void
  145. newstdwin()
  146. {
  147.     TEXTWIN *t;
  148.  
  149.     if ((getprogname(fname) == OK) &&
  150.         (getargs(fname, argstr) == OK) ) {
  151.         t = newproc(fname, argstr, progpath, 0, 0, stdcol, stdrow, stdscroll,
  152.             default_kind, default_font, default_height);
  153.         if (t)
  154.             open_window(t->win);
  155.     }
  156. }
  157.  
  158. void
  159. newaltwin()
  160. {
  161.     TEXTWIN *t;
  162.  
  163.     if ((getprogname(fname) == OK) &&
  164.         (getargs(fname, argstr) == OK) ) {
  165.         t = newproc(fname, argstr, progpath, 0, 0, altcol, altrow, altscroll,
  166.             default_kind, default_font, default_height);
  167.         if (t)
  168.             open_window(t->win);
  169.     }
  170. }
  171.  
  172. void
  173. get_winsize(colptr, rowptr, sptr)
  174.     int *colptr, *rowptr, *sptr;
  175. {
  176.     int x, y, w, h, i;
  177.     TEDINFO *ted;
  178.     char *rowstr, *colstr, *scrstr;
  179.     int row, col, scroll;
  180.  
  181.     row = *rowptr;
  182.     col = *colptr;
  183.     scroll = *sptr;
  184.  
  185.     ted = (TEDINFO *)winsize_dialog[ROWBOX].ob_spec;
  186.     rowstr = (char *)ted->te_ptext;
  187.     strcpy(rowstr, valdec(row));
  188.     ted = (TEDINFO *)winsize_dialog[COLBOX].ob_spec;
  189.     colstr = (char *)ted->te_ptext;
  190.     strcpy(colstr, valdec(col));
  191.     ted = (TEDINFO *)winsize_dialog[SCRBOX].ob_spec;
  192.     scrstr = (char *)ted->te_ptext;
  193.     strcpy(scrstr, valdec(scroll));
  194.  
  195.     form_center(winsize_dialog, &x, &y, &w, &h);
  196.  
  197.     wind_update(1);
  198.     form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
  199.     if (win_flourishes)
  200.         form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
  201.  
  202.     objc_draw(winsize_dialog, 0, 2, x, y, w, h);
  203.  
  204.     i = form_do(winsize_dialog, COLBOX);
  205.  
  206.     if (win_flourishes)
  207.         form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
  208.  
  209.     form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
  210.     objc_change(winsize_dialog, i, 0, x, y, w, h, NORMAL, 0);
  211.     wind_update(0);
  212.     if (i != WINSIZOK) return;
  213.  
  214.     col = decval(colstr);
  215.     if (col < MINCOLS) col = MINCOLS; else if (col > MAXCOLS) col = MAXCOLS;
  216.     row = decval(rowstr);
  217.     if (row < MINROWS) row = MINROWS; else if (row > MAXROWS) row = MAXROWS;
  218.     scroll = decval(scrstr);
  219.     if (scroll < 0) scroll = 0;
  220.  
  221.     *colptr = col;
  222.     *rowptr = row;
  223.     *sptr = scroll;
  224. }
  225.  
  226. void
  227. set_altsiz()
  228. {
  229.     get_winsize(&altcol, &altrow, &altscroll);
  230. }
  231.  
  232. /*
  233.  * set the line A variables and stdcol and
  234.  * stdrow.
  235.  */
  236. void
  237. set_linea(ncol, nrow)
  238.     int ncol, nrow;
  239. {
  240.     lineAset = 1;
  241.     stdrow = nrow;
  242.     stdcol = ncol;
  243.     V_CEL_MX = stdcol - 1;
  244.     V_CEL_MY = stdrow - 1;
  245. }
  246.  
  247. void
  248. set_stdsiz()
  249. {
  250.     int ncol, nrow;
  251.  
  252.     ncol = stdcol;
  253.     nrow = stdrow;
  254.     get_winsize(&ncol, &nrow, &stdscroll);
  255.     set_linea(ncol, nrow);
  256. }
  257.  
  258. void
  259. set_winsiz()
  260. {
  261.     TEXTWIN *t;
  262.     int row, col, scroll;
  263.     struct winsize tw;
  264.  
  265.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  266.         t = gl_topwin->extra;
  267.         row = NROWS(t);
  268.         col = NCOLS(t);
  269.         scroll = SCROLLBACK(t);
  270.         get_winsize(&col, &row, &scroll);
  271.         if (col != NCOLS(t) || row != NROWS(t) ||
  272.             scroll != SCROLLBACK(t)) {
  273.             curs_off(t);
  274.             resize_textwin(t, col, row, scroll);
  275.             curs_on(t);
  276.             tw.ws_row = row;
  277.             tw.ws_col = col;
  278.             tw.ws_xpixel = tw.ws_ypixel = 0;
  279.             (void)Fcntl(t->fd, &tw, TIOCSWINSZ);
  280.             (void)Pkill(-t->pgrp, SIGWINCH);
  281.         }
  282.     }
  283. }
  284.  
  285. void
  286. set_wintitle()
  287. {
  288.     WINDOW *v;
  289.     OBJECT *titledial;
  290.     TEDINFO *ted;
  291.     char *titlestr;
  292.     int x, y, w, h, ret;
  293.  
  294.     v = gl_topwin;
  295.     if (v && v->wtype == TEXT_WIN) {
  296.         rsrc_gaddr(0, TITLDIAL, &titledial);
  297.         ted = (TEDINFO *)titledial[TITLSTR].ob_spec;
  298.         titlestr = (char *)ted->te_ptext;
  299.         strncpy(titlestr, v->wi_title, 32);
  300.  
  301.         form_center(titledial, &x, &y, &w, &h);
  302.         wind_update(1);
  303.         form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
  304.         if (win_flourishes)
  305.             form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
  306.         objc_draw(titledial, 0, 2, x, y, w, h);
  307.         ret = form_do(titledial, TITLSTR);
  308.         if (win_flourishes)
  309.             form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
  310.         form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
  311.  
  312.         objc_change(titledial, ret, 0, x, y, w, h, NORMAL, 0);
  313.         wind_update(0);
  314.         if (ret != TITLOK) return;
  315.         title_window(v, titlestr);
  316.     }
  317. }
  318.  
  319. /* shut down all windows */
  320. void
  321. shutdown()
  322. {
  323.     WINDOW *w;
  324.  
  325.     for (w = gl_winlist; w; w = w->next)
  326.         (*w->closed)(w);
  327. }
  328.  
  329. void
  330. quit()
  331. {
  332.     if (_app) {
  333.         gl_done = 1;
  334.         shutdown();
  335.     }
  336. }
  337.  
  338. void
  339. do_cut()
  340. {
  341.     extern void cut(), paste_to_desk();
  342.     extern char *cliptext;
  343.     int x, y;
  344.  
  345.     if (gl_topwin) {
  346.         cut(gl_topwin);
  347.         objc_offset(deskobj, CLIPICN, &x, &y);
  348.         if (cliptext)
  349.             paste_to_desk(x+1, y+1);
  350.     }
  351. }
  352.  
  353. void
  354. do_paste()
  355. {
  356.     extern char *read_scrap();
  357.     extern void paste();
  358.     extern char *cliptext;
  359.  
  360.     if (!gl_topwin) return;
  361.  
  362.     if (cliptext)
  363.         free(cliptext);
  364.  
  365.     cliptext = read_scrap("SCRAP.TXT");
  366.     if (!cliptext) {
  367.         form_alert(1, AlertStrng(SCRAPDAT));
  368.         return;
  369.     }
  370.     paste(gl_topwin);
  371. }
  372.  
  373. void
  374. set_wfont()
  375. {
  376.     int font, point;
  377.     int i;
  378.     TEXTWIN *t;
  379.  
  380.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  381.         t = gl_topwin->extra;
  382.         font = t->cfont;
  383.         point = t->cpoints;
  384.         i = get_font(&font, &point);
  385.         if (i == OK)
  386.             textwin_setfont(t, font, point);
  387.     }
  388. }
  389.  
  390. void
  391. set_dfont()
  392. {
  393.     int font, point;
  394.  
  395.     font = default_font;
  396.     point = default_height;
  397.  
  398.     if (get_font(&font, &point) == OK) {
  399.         default_font = font;
  400.         default_height = point;
  401.     }
  402. }
  403.  
  404. /*
  405.  * functions for setting window gadgets
  406.  * if "info_ok" is nonzero, we allow the
  407.  * user to select the INFO line, otherwise
  408.  * not. "kindptr" points to the current
  409.  * settings on input, and is set to the
  410.  * new settings on output.
  411.  */
  412.  
  413. void
  414. get_gadgets(kindptr, info_ok)
  415.     int *kindptr;
  416.     int info_ok;
  417. {
  418.     OBJECT *gadgdial;
  419.     int kind = *kindptr;
  420.     int ret;
  421.     int x, y, w, h;
  422.     int doubleclick = 0;
  423.  
  424.     rsrc_gaddr(0, GADGDIAL, &gadgdial);
  425.     form_center(gadgdial, &x, &y, &w, &h);
  426.  
  427. /* make info_ok a mask */
  428.     if (info_ok)
  429.         info_ok = ~0;
  430.     else
  431.         info_ok = ~INFO;
  432.  
  433.     wind_update(1);
  434.  
  435.     form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
  436.     if (win_flourishes)
  437.         form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
  438.  
  439. redisplay:
  440.     gadgdial[GCLOSER].ob_state = (kind & CLOSER) ? SELECTED : NORMAL;
  441.     gadgdial[GTITLE].ob_state = (kind & MOVER) ? SELECTED : NORMAL;
  442.     if (info_ok & INFO) {
  443.         gadgdial[GMENU].ob_state = (kind & INFO) ? SELECTED : NORMAL;
  444.     } else {
  445.         gadgdial[GMENU].ob_state = DISABLED;
  446.     }
  447.     gadgdial[GFULLER].ob_state = (kind & FULLER) ? SELECTED : NORMAL;
  448.     gadgdial[GVSLIDE].ob_state = (kind & VSLIDE) ? SELECTED : NORMAL;
  449.     gadgdial[GHSLIDE].ob_state = (kind & HSLIDE) ? SELECTED : NORMAL;
  450.     gadgdial[GSIZER].ob_state = (kind & SIZER) ? SELECTED : NORMAL;
  451.     objc_draw(gadgdial, 0, 2, x, y, w, h);
  452.     ret = form_do(gadgdial, 0);
  453.     if (ret & 0x8000) {
  454.         doubleclick = 1;
  455.         ret &= 0x7fff;
  456.     }
  457.     if (ret == GALLGAD) {
  458.         kind = ALLGADGETS & info_ok; if (!doubleclick) goto redisplay;
  459.     } else if (ret == GTOPGAD) {
  460.         kind = MINGADGETS & info_ok; if (!doubleclick) goto redisplay;
  461.     } else if (ret == GNOGAD) {
  462.         kind = NOGADGETS; if (!doubleclick) goto redisplay;
  463.     } else if (ret == GADGOK) {
  464.         kind = 0;
  465.         if (gadgdial[GCLOSER].ob_state == SELECTED)
  466.             kind |= CLOSER;
  467.         if (gadgdial[GFULLER].ob_state == SELECTED)
  468.             kind |= FULLER;
  469.         if (gadgdial[GSIZER].ob_state == SELECTED)
  470.             kind |= SIZER;
  471.         if (gadgdial[GTITLE].ob_state == SELECTED)
  472.             kind |= (NAME|MOVER);
  473.         if (gadgdial[GMENU].ob_state == SELECTED)
  474.             kind |= INFO;
  475.         if (gadgdial[GVSLIDE].ob_state == SELECTED)
  476.             kind |= (UPARROW|DNARROW|VSLIDE);
  477.         if (gadgdial[GHSLIDE].ob_state == SELECTED)
  478.             kind |= (LFARROW|RTARROW|HSLIDE);
  479.     } else if (ret == GADGCAN) {
  480.         kind = *kindptr;
  481.     }
  482.  
  483.     if (win_flourishes)
  484.         form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
  485.     form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
  486.     wind_update(0);
  487.  
  488.     gadgdial[ret].ob_state = NORMAL;
  489.  
  490.     *kindptr = kind;
  491. }
  492.  
  493. void
  494. set_wkind()
  495. {
  496.     int kind;
  497.  
  498.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  499.         kind = gl_topwin->wi_kind;
  500.         get_gadgets(&kind, gl_topwin->menu ? 1 : 0);
  501.         change_window_gadgets(gl_topwin, kind);
  502.     }
  503. }
  504.  
  505. void
  506. set_dkind()
  507. {
  508.     get_gadgets(&default_kind, 1);
  509. }
  510.  
  511. /*
  512.  * function that toggles an (integer) on/off switch in the global menu
  513.  */
  514.  
  515. void
  516. toggle(var)
  517.     int *var;
  518. {
  519.     ENTRY *e;
  520.     MENU *m = globalmenu;
  521.     WINDOW *v;
  522.     int x, y, w, h;
  523.  
  524.     *var = !*var;
  525.     for (e = m->contents; e; e = e->next) {
  526.         if (e->arg == var)
  527.             break;
  528.     }
  529.  
  530.     if (e) {
  531.         if (*var) {
  532.             check_entry(m, e);
  533.         } else {
  534.             uncheck_entry(m, e);
  535.         }
  536.     }
  537.  
  538.     if (var == &align_windows && *var) {
  539.         for(v = gl_winlist; v; v = v->next) {
  540.             if (v->wtype == TEXT_WIN && v->wi_handle >= 0) {
  541.                 wind_get(v->wi_handle, WF_CURRXYWH, &x,
  542.                     &y, &w, &h);
  543.                 (*v->moved)(v, x, y, w, h);
  544.             }
  545.         }
  546.     }
  547. }
  548.  
  549. /* bury the topmost window */
  550.  
  551. void
  552. bury()
  553. {
  554.     new_topwin(0);
  555. }
  556.  
  557. /* redraw the whole screen */
  558.  
  559. void
  560. doredraw()
  561. {
  562.     sys_menu = 1;
  563. #ifdef GLOBAL_APPL_MENUS
  564.     if (gl_topwin && gl_topwin->wtype == TEXT_WIN) {
  565.         if (gl_topwin->menu && appl_menus) {
  566.             sys_menu = 0;
  567.             show_menu(gl_topwin->menu);
  568.         }
  569.     }
  570. #endif
  571.     if (sys_menu)
  572.         show_menu(sysbar);
  573.  
  574.     redraw_screen(xdesk, ydesk, wdesk, hdesk);
  575. }
  576.  
  577. void
  578. dieloop()
  579. {
  580.     int msgbuff[8];
  581.  
  582.     for(;;) {
  583.         (void)evnt_mesag(msgbuff);
  584.     }
  585. }
  586.  
  587. static void (*oldttop)();
  588.  
  589. static void
  590. tooltop(v)
  591.     WINDOW *v;
  592. {
  593.     extern void top_menu();
  594.  
  595.     top_menu(v, oldttop);
  596. }
  597.  
  598. void
  599. toolclose(v)
  600.     WINDOW *v;
  601. {
  602.     if (!_app)
  603.         ac_close();
  604.     else {
  605.         showtools = 0;
  606.         close_window(v);
  607.     }
  608. }
  609.  
  610. void
  611. toolopen()
  612. {
  613.     if (showtools) {
  614.         (*toolwindow->topped)(toolwindow);
  615.     } else {
  616.         showtools = 1;
  617.         open_window(toolwindow);
  618.     }
  619. }
  620.  
  621. char *Strng(index)
  622.     int index;
  623. {
  624.     char *addr;
  625.  
  626.     addr = 0;
  627.     rsrc_gaddr(5, index, &addr);
  628.     return addr;
  629. }
  630.  
  631. int __mint;
  632.  
  633. /*
  634.  * get MiNT version number
  635.  */
  636.  
  637. static void
  638. getMiNT()
  639. {
  640.     long *cookie;
  641.  
  642. /* get the system time in 200HZ ticks from the BIOS _hz_200 variable */
  643.  
  644.     cookie = *((long **) 0x5a0L);
  645.     if (!cookie)
  646.         __mint = 0;
  647.     else {
  648.         while (*cookie) {
  649.             if (*cookie == 0x4d694e54L) {    /* MiNT */
  650.                 __mint = (int) cookie[1];
  651.                 return;
  652.             }
  653.             cookie += 2;
  654.         }
  655.     }
  656.     __mint = 0;
  657. }
  658.  
  659. int
  660. main()
  661. {
  662.     extern short _global[];        /* AES global array */
  663.     int i;
  664.  
  665. #ifdef WWA_RUN_TOSWIN
  666. /* Before ANYTHING, open up the TOSRUN pipe, so that RUNTOS can use it */
  667.     trun_fd = Fcreate("U:\\PIPE\\TOSRUN", global_flag);
  668. #endif
  669.  
  670.     (void)Supexec(getMiNT);
  671.     init_gem();
  672.     if (_global[1] == -1) {        /* multitasking AES? */
  673.         MultiTOS = 1;
  674.     } else {
  675.         if (_app)
  676.             (void)Cursconf(0, 0);    /* hide cursor */
  677.         else {
  678.             oldACC = 1;
  679.             global_flag = 0x1000;
  680.             termfunc = (long)Setexc(0x102, -1L);
  681.             heapbase = (void *)Malloc(heapsize);
  682.             if (__mint == 0 ||
  683.                (heapbase = (void *)Malloc(heapsize)) == 0)
  684.             {
  685.                 close_vwork();
  686.                 while(1) evnt_loop();
  687.             }
  688.         }
  689.     }
  690.  
  691.     linea0();
  692.     toolx = xdesk;
  693.     tooly = ydesk;
  694.     graf_mouse(BEE, 0L);
  695.     i = rsrc_load("TOSWIN_W.RSC");
  696.     if (i == 0) {
  697.         form_alert(1, "[3][TOSWIN_W.RSC not found][Cancel]");
  698.         if (oldACC)
  699.             dieloop();
  700.         else {
  701.             exit_gem(1);
  702.         }
  703.     }
  704.     graf_mouse(ARROW, 0L);
  705.  
  706.     if (
  707.         rsrc_gaddr(0, DESKTOP, &deskobj) == 0 ||
  708.         rsrc_gaddr(0, MENUDEF, &menudef_dialog) == 0 ||
  709.         rsrc_gaddr(0, WINSIZE, &winsize_dialog) == 0 ||
  710.         rsrc_gaddr(0, FNTDIAL, &fontdial) == 0 ||
  711.         rsrc_gaddr(0, CUTOPTS, &cutdialog) == 0) {
  712.         form_alert(1, "[3][TOSWIN.RSC corrupted??][Cancel]");
  713.         if (oldACC)
  714.             dieloop();
  715.         else
  716.             exit_gem(1);
  717.     }
  718.  
  719.     if (MultiTOS || oldACC) {
  720.         menu_register(gl_apid, Strng(TOSPROGS));
  721.     }
  722.     init_fontdesc();
  723.     gl_timer = MultiTOS ? LONGWAIT : NOMULTIWAIT;
  724.     fn_timeout = oldACC ? acc_input : fd_input;
  725.     fn_message = iconify_message;
  726.     fn_mouse = desk_mouse;
  727.  
  728.     about_string = Strng(ABOUTTW);
  729.     about_func = toolopen;
  730.  
  731.     sysbar = filemenu = create_menu(Strng(SFILE));
  732.     (void)add_entry(filemenu, Strng(SOPNSTD), newstdwin, NULL, 0, NORMAL);
  733.     (void)add_entry(filemenu, Strng(SOPNALT), newaltwin, NULL, 0, NORMAL);
  734.     closeentry = add_entry(filemenu, Strng(SCLOSE), g_close, NULL,
  735.              0, DISABLED);
  736.     (void)add_entry(filemenu, "---", about_func, NULL, 0, DISABLED);
  737.     (void)add_entry(filemenu, Strng(SLOADCFG), load_config, NULL, 0, NORMAL);
  738.     (void)add_entry(filemenu, Strng(SSAVECFG), save_config, NULL, 0, NORMAL);
  739.     (void)add_entry(filemenu, "---", about_func, NULL, 0, DISABLED);
  740.     (void)add_entry(filemenu, Strng(SSETMENU), config_menu, sysbar,
  741.              0, NORMAL);
  742.     (void)add_entry(filemenu, "---", quit, NULL, 0, DISABLED);
  743.     (void)add_entry(filemenu, Strng(SQUIT), quit, NULL, 0, oldACC ? DISABLED : NORMAL);
  744.  
  745.     editmenu = create_menu(Strng(SEDIT));
  746.     copyentry = add_entry(editmenu, Strng(SCOPY), do_cut, NULL, 0, NORMAL);
  747.     pasteentry = add_entry(editmenu, Strng(SPASTE), do_paste, NULL, 0, NORMAL);
  748.     (void)add_entry(editmenu, "---", about_func, NULL, 0, DISABLED);
  749.     (void)add_entry(editmenu, Strng(SPASTEOP), setcutoptions, NULL, 0, NORMAL);
  750.     filemenu->next = editmenu;
  751.  
  752.     globalmenu = create_menu(Strng(SGLOBAL));
  753.     (void)add_entry(globalmenu, Strng(SALIGNW), toggle, &align_windows,
  754.              0, NORMAL);
  755. #ifdef GLOBAL_APPL_MENUS
  756.     (void)add_entry(globalmenu, Strng(SAPPMENU), togglemenu, &appl_menus,
  757.              0, CHECKED);
  758. #else
  759.     (void)add_entry(globalmenu, Strng(SAPPMENU), toggle, &appl_menus,
  760.              0, CHECKED);
  761. #endif
  762.     (void)add_entry(globalmenu, Strng(SAUTOCL), toggle, &autoclose, 0, NORMAL);
  763.     (void)add_entry(globalmenu, Strng(SFLOURIS), toggle, &win_flourishes,
  764.              0, CHECKED);
  765.     (void)add_entry(globalmenu, Strng(SPTTYPE), toggle, &point_to_type,
  766.              0, NORMAL);
  767.     (void)add_entry(globalmenu, Strng(SSMOOTH), toggle, &smoothscroll,
  768.              0, NORMAL);
  769. #ifdef WWA_AUTO_RAISE
  770.     (void)add_entry(globalmenu, Strng(AUTORAIS), toggle, &auto_raise,
  771.              0, NORMAL);
  772. #endif
  773.     (void)add_entry(globalmenu, "---", about_func, NULL, 0, DISABLED);
  774.     (void)add_entry(globalmenu, Strng(SSETSTD), set_stdsiz, NULL,
  775.              0, NORMAL);
  776.     (void)add_entry(globalmenu, Strng(SSETALT), set_altsiz, NULL,
  777.              0, NORMAL);
  778.     (void)add_entry(globalmenu, Strng(SSETDFNT), set_dfont, NULL,
  779.              0, NORMAL);
  780.     (void)add_entry(globalmenu, Strng(SSETDGAD), set_dkind, NULL,
  781.              0, NORMAL);
  782.     (void)add_entry(globalmenu, "---", about_func, NULL, 0, DISABLED);
  783.     (void)add_entry(globalmenu, Strng(SENVIRON), setenvoptions, NULL,
  784.              0, NORMAL);
  785.     (void)add_entry(globalmenu, "---", about_func, NULL, 0, DISABLED);
  786.     (void)add_entry(globalmenu, Strng(SREDRAW), doredraw, NULL,
  787.              0, NORMAL);
  788.     editmenu->next = globalmenu;
  789.  
  790.     windowmenu = create_menu(Strng(SWINDOW));
  791.     (void)add_entry(windowmenu, Strng(SBURY), bury, NULL, 0, DISABLED);
  792.     (void)add_entry(windowmenu, Strng(SICONIFY), iconify_topwin,
  793.              NULL, 0, DISABLED);
  794.     (void)add_entry(windowmenu, "---", about_func, NULL, 0, DISABLED);
  795.     (void)add_entry(windowmenu, Strng(SLITERAL), send_char,
  796.             NULL, 0, DISABLED);
  797.     (void)add_entry(windowmenu, "---", about_func, NULL, 0, DISABLED);
  798.     (void)add_entry(windowmenu, Strng(SSETWSIZ), set_winsiz, NULL,
  799.              0, DISABLED);
  800.     (void)add_entry(windowmenu, Strng(SSETWFNT), set_wfont, NULL,
  801.              0, DISABLED);
  802.     (void)add_entry(windowmenu, Strng(SSETWGAD), set_wkind, NULL,
  803.              0, DISABLED);
  804.     (void)add_entry(windowmenu, Strng(SSETWTIT), set_wintitle, NULL,
  805.              0, DISABLED);
  806.     globalmenu->next = windowmenu;
  807.  
  808.     gadgmenu = create_menu(Strng(SGADGETS));
  809.     (void)add_entry(gadgmenu, Strng(STOGFULL), g_full, NULL, 0, DISABLED);
  810.     (void)add_entry(gadgmenu, Strng(SMOVE), g_move, NULL, 0, DISABLED);
  811.     (void)add_entry(gadgmenu, Strng(SSCRUP), g_scroll, (void *)(long)WA_UPLINE,
  812.             0, DISABLED);
  813.     (void)add_entry(gadgmenu, Strng(SSCRDOWN), g_scroll, (void *)(long)WA_DNLINE,
  814.             0, DISABLED);
  815.     (void)add_entry(gadgmenu, Strng(SSCRLEFT), g_scroll, (void *)(long)WA_LFLINE,
  816.             0, DISABLED);
  817.     (void)add_entry(gadgmenu, Strng(SSCRRIGH), g_scroll, (void *)(long)WA_RTLINE,
  818.             0, DISABLED);
  819.     windowmenu->next = gadgmenu;
  820.  
  821.     if (!oldACC) {
  822. #ifdef OLD_WAY
  823.         (void)Psignal(SIGCHLD, dead_kid);
  824. #endif
  825.         (void)Psignal(SIGINT, send_sig);
  826.         (void)Psignal(SIGQUIT, send_sig);
  827.         (void)Psignal(SIGHUP, send_sig);
  828.         (void)Psignal(SIGTSTP, send_sig);
  829.         (void)Psignal(SIGTTIN, ignore);
  830.         (void)Psignal(SIGTTOU, ignore);
  831.     }
  832.  
  833. #ifndef WWA_RUN_TOSWIN
  834. /* open up the TOSRUN pipe, so that the desktop can tell us to run stuff */
  835.     trun_fd = Fcreate("U:\\PIPE\\TOSRUN", global_flag);
  836. #endif
  837.  
  838.     if (trun_fd <= 0)
  839.         trun_fd = 0;
  840.     else {
  841.         if (!oldACC)
  842.             fd_mask |= (1L << trun_fd);
  843.         (void)Fcntl(trun_fd, (long)O_NDELAY, F_SETFL);
  844.     }
  845.  
  846. /* set up window sizes */
  847. /* the standard size always matches the line A size; the alt size is
  848.  * settable by the user
  849.  */
  850.  
  851.     stdrow = lineArow = V_CEL_MY+1; stdcol = lineAcol = V_CEL_MX+1;
  852.     altrow = (stdrow == 50) ? 25 : 50; altcol = 80;
  853.  
  854.     vsf_perimeter(vdi_handle, 0);    /* no bars around perimeter */
  855.  
  856.     show_menu(sysbar);    /* show_menu checks _app */
  857.  
  858. /* try to load a standard config file */
  859.     i = shel_find(stdconfig);
  860.     if (i != 0) {
  861.         load_config(stdconfig);
  862.     }
  863.  
  864.     if (!_app)
  865.         showtools = 1;
  866.  
  867.     i = CLOSER|MOVER|NAME;
  868.     if (!_app) i |= INFO;
  869.  
  870.     toolwindow = create_objwin(deskobj, "TOSWIN", i,
  871.              toolx, tooly, deskobj[0].ob_width, deskobj[0].ob_height);
  872.     if (!_app) {
  873.         toolwindow->menu = filemenu;
  874.         toolwindow->infostr = strdup(menustr(filemenu));
  875.     }
  876.     oldttop = toolwindow->topped;
  877.     toolwindow->topped = tooltop;
  878.     toolwindow->closed = toolclose;
  879.  
  880.     if (_app && showtools)
  881.         open_window(toolwindow);
  882.  
  883.     if (oldACC)
  884.         close_vwork();
  885.  
  886. #ifdef WWA_INITIAL_REDRAW
  887. /*
  888.  *  Warwick Allison - Initial Redraw extension:
  889.  *
  890.  *          Redraw at startup if not MultiTOS.
  891.  */
  892.     if (!MultiTOS) doredraw();
  893. #endif
  894.  
  895.     evnt_loop();
  896.  
  897.     if (lineAset) {
  898.         V_CEL_MX = lineAcol - 1;
  899.         V_CEL_MY = lineArow - 1;
  900.     }
  901.     exit_gem(0);
  902.     return 0;
  903. }
  904.  
  905. /*
  906.  * functions for when we are accessories
  907.  */
  908.  
  909. int opened = 0;
  910.  
  911. void
  912. ac_open()
  913. {
  914.     WINDOW *w;
  915.  
  916.     if (!opened) {
  917.         open_vwork();
  918.         vsf_perimeter(vdi_handle, 0);
  919.         for (w = gl_winlist; w; w = w->next) {
  920.             if (open_window(w))
  921.                 opened = 1;
  922.         }
  923.         if (opened) return;
  924.         if (gl_winlist) {    /* bad error */
  925.             form_alert(1, AlertStrng(NOOPEN));
  926.             close_vwork();
  927.             return;
  928.         }
  929.     }
  930.     toolopen();
  931.     if (!gl_winlist) {
  932.         close_vwork();
  933.         opened = 0;
  934.     }
  935.     if (lineAset) {
  936.         set_linea(stdcol, stdrow);
  937.     }
  938. }
  939.  
  940. void
  941. ac_close()
  942. {
  943.     WINDOW *w;
  944.  
  945.     if (!opened) return;
  946.  
  947.     for (w = gl_winlist; w; w = w->next)
  948.         close_window(w);
  949.     close_vwork();
  950.     opened = 0;
  951.     if (lineAset) {
  952.         V_CEL_MX = lineAcol - 1;
  953.         V_CEL_MY = lineArow - 1;
  954.     }
  955. }
  956.  
  957. /* called when we get an AC_CLOSE message; this tells us that our
  958.  * windows have been forcibly deleted on us
  959.  */
  960.  
  961. void
  962. force_ac_close()
  963. {
  964.     WINDOW *w;
  965.  
  966.     if (opened) {
  967.         for (w = gl_winlist; w; w = w->next) {
  968.             w->wi_handle = -1;
  969.         }
  970.         close_vwork();
  971.         opened = 0;
  972.     }
  973. }
  974.  
  975.  
  976. /*
  977.  * special sbrk() stuff; note that this requires the MiNT
  978.  * library
  979.  */
  980.  
  981. void *
  982. _sbrk(sz)
  983.     long sz;
  984. {
  985.     void *foo;
  986.  
  987.     sz = (sz + 7) & ~((unsigned long)7L);
  988.  
  989.     if (heapbase) {
  990.         if (sz >= heapsize) return 0;
  991.         foo = heapbase;
  992.         heapbase = (void *)((char *)heapbase + sz);
  993.         heapsize -= sz;
  994.     } else {
  995.         foo = (void *)Malloc(sz);
  996.     }
  997.     return foo;
  998. }
  999.  
  1000. void *
  1001. sbrk(sz)
  1002.     size_t sz;
  1003. {
  1004.     return _sbrk((long)sz);
  1005. }
  1006.